<!DOCTYPE html>
<html>

<head>
    <title>{$data['title']|default="帖子详情"}</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content=" ">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/public/static/libs/weui/lib/mui.min.css"/>
    <link rel="stylesheet" href="/public/static/libs/weui/lib/weui.min.css">
    <link rel="stylesheet" href="/public/static/topic/css/jquery-weui.css">
    <link rel="stylesheet" href="/public/static/topic/css/style.css"/>
    {if condition="$android eq 0"}
    <link rel="stylesheet" href="/public/static/libs/weui/lib/preview.css">
    {/if}
</head>

<style type="text/css">    *{-moz-user-select:none;-moz-user-select:text;-moz-user-select:all;-webkit-user-select:none;-webkit-user-select:text;-ms-user-select:none;-ms-user-select:text;-ms-user-select:element}div{-moz-user-select:none;-moz-user-select:text;-webkit-user-select:none;-webkit-user-select:text;-ms-user-select:none;-ms-user-select:text;-ms-user-select:element}p{-moz-user-select:none;-moz-user-select:text;-webkit-user-select:none;-webkit-user-select:text;-ms-user-select:none;-ms-user-select:text;-ms-user-select:element}h3{-moz-user-select:none;-moz-user-select:text;-moz-user-select:all;-webkit-user-select:none;-webkit-user-select:text;-ms-user-select:none;-ms-user-select:text;-ms-user-select:all;-ms-user-select:element}span{-moz-user-select:none;-moz-user-select:text;-webkit-user-select:none;-webkit-user-select:text;-ms-user-select:none;-ms-user-select:text;-ms-user-select:element}body{max-width:100%;background:#fff !important}.mui-content{background:#fff}.send_detail .head-img{overflow:hidden;padding:0 .5rem;height:2.5rem}.send_detail .head-img > img{float:left;width:1.8rem;height:1.8rem;border-radius:1rem}.send_detail .head-info{width:80%}.send_detail .head-info p:first-of-type{height:1rem;line-height:1rem;font-size:.7rem;color:#222}.send_detail .head_icon{float:right;margin-left:10px}.send_detail .head_icon img{width:20px;height:20px;vertical-align:middle}.send_detail .news_zixun{padding:0 .5rem;border-bottom:1px solid #eee}.send_detail .news_zixun .news_zixun_title{height:auto;color:#555;display:-webkit-box;-webkit-box-orient:vertical;overflow:hidden;font-size:.8rem;margin:.5rem 0;-ms-word-wrap:;word-wrap: break-word}.send_detail .news_zixun .news_zixun_img{overflow:hidden}.send_detail .news_zixun .news_zixun_img img{float:left;width:31.6%;margin-right:2.6%;margin-bottom:.5rem}.send_detail .news_zixun .news_zixun_img img:nth-of-type(3n){margin-right:0}.send_detail .bg_bar{width:100%;height:.5rem;background:#f4f4f4}.topic_tle{padding:.5rem;font-size:1rem}.score_width{width:160px}.floor{color:#5A5A5A;font-size:12px}.edit{display:inline-block;height:26px;overflow:hidden;float:right}.edit img{width:26px;height:26px;float:left;margin-top:5px}.score{float:left}.get_score_desc{font-size:12px}.get_score_desc span:nth-of-type(1){margin-right:5px}.get_score_body{overflow:hidden;padding-top:.3rem}.get_score{padding:.5rem}.score_box{float:left;overflow:hidden;height:1.8rem}.score_box img{border-radius:18px}.right_commen{float:right;position:relative}.right_commen:after{content:'';height:30px;width:3px;background:#ddd;position:absolute;left:-8px;top:5px;border-radius:1.5px}.replay{background:#ddd;color:#5A5A5A}.comments{font-size:.8rem}.comments img{width:31.6%;margin-right:2.6%;float:left;height:60px}.comments img:nth-of-type(3n){margin-right:0}.comment-content .emotion{width:1rem;height:1rem}blockquote{background-color:#efebe9;padding:5px;border-radius:5px;font-size:15px}blockquote font font{display:block}.show_score{float:left;display:inline-block}.jifen{box-shadow:0 0 1px #d81e06;height:1rem;width:3rem;overflow:hidden;margin-top:.4rem;display:flex;flex-direction:row;justify-content:center;align-items:center;font-size:12px;border-radius:3px;margin-left:10px;color:#D81E06}.jifen img{width:.7rem;height:.7rem;vertical-align:middle;margin-right:2px}.mui-popup-text{text-align:center;text-indent:2em;.}.reason{margin-top:5px}textarea{padding:0;height:50px;font-size:14px}.mui-popup-text{text-indent:0}.reason_tip{margin:10px 0;color:#000;text-align:left;text-indent:2em}.weui-loadmore__tips{color:#a5a5a5}.reward_box{display:flex;flex-direction:row;justify-content:space-around;flex-wrap:wrap;margin-top:10px}.reward_box span{display:block;color:#5a5a5a;font-size:16px;border:1px solid #f00;border-radius:5px;width:30%;margin-bottom:.5rem}.reward_check{background:#f00;color:#fff!important;border:none!important}.money-change{width:100%}.hidemoney{display:none;margin:0!important}#reword{display:flex;flex-direction:column;justify-content:center;align-content:center;align-items:center}.award{text-align:center;width:3rem;height:3rem;line-height:3rem;border-radius:1.5rem;background:#f00;color:#fff;font-weight:bold;font-size:20px;box-shadow:0 0 10px #f00;margin:.5rem 0}.sort_comment{padding:0 .5rem;height:2rem;line-height:2rem;display:flex;flex-direction:row;justify-content:space-between}.sort_comment span{font-size:16px;color:#5a5a5a}.select_sort img{width:15px;height:15px;vertical-align:middle;margin-right:5px}</style>
<script src="/public/static/libs/weui/lib/fastclick.js"></script>

<style>
	.send_detail .head-info {
    width: 87%;
}
.head-img{width:100%;margin: 0;padding:.5rem!important;display: flex;flex-direction: row;justify-content: space-between;height:3rem!important}
	.follow{
		font-size: 14px;
		color: #fff;
		/*padding: 6px 16px;*/
		height: 28px;
		line-height: 28px;
		text-align: center;
		border-radius: 4px;;
		right: 0;
		top:6px;
		display: block;
		width: 3.4rem;
		background:#2277ff;
		position: absolute;
		
	}
	.xuanfu{
		position:fixed;
		left:0;
		top:0;
		background: #fff;
		z-index: 99999;
		box-shadow: 0 2px 2px 2px #f5f5f5;
	}
	.head-info{
		position: relative;
		overflow: hidden;
	}
	
	
</style>
<body>
<!-- body 顶部加上如下代码 -->
{if condition="$android"}
<div class="weui-pull-to-refresh__layer" style="margin-bottom: 15px">
    <div class='weui-pull-to-refresh__arrow'></div>
    <div class='weui-pull-to-refresh__preloader'></div>
    <div class="down">下拉刷新</div>
    <div class="up">释放刷新</div>
    <div class="refresh">正在刷新</div>
</div>
{/if}
<div class="send_detail">
	<div class="head-img xuanfu" style="display: none;">
        <img src="{$data['avatar']}" data-id="{$data['uid']}" class="avatar-img">
        <div class="head-info">
            <p><span>{$data['username']}</span></p>
            <p>
                <span>{$data['ctime']}</span>
                
            </p>
            <span class="follow">关注</span>
        </div>
    </div>
    
    <div class="topic_tle">{$data['title']}</div>
    
    <div class="head-img" id="follow">
        <img src="{$data['avatar']}" data-id="{$data['uid']}" class="avatar-img">
        <div class="head-info">
            <p><span>{$data['username']}</span></p>
            <p>
                <span>{$data['ctime']}</span>
                <span class="head_icon"><img
                        src="/public/static/topic/img/commen.png"> {$data['pcounts']}</span>
                <span class="head_icon"><img
                        src="/public/static/topic/img/read.png"> {$data['readcount']}</span>
            </p>
            <span class="follow">关注</span>
        </div>
    </div>

    <div class="send_box">
        <div class="news_zixun">
            <p class="news_zixun_title">{$data['content']}</p>
            {notempty name="data['pics']"}
            <div class="news_zixun_img">
                {volist name="data['pics']" id="vo" key="k"}
                <!--<img class="lazy" data-lazyload="{$vo}" data-preview-src="{php}echo strtr($vo,['/thumb/'=>'/']){/php}" data-preview-group="1" src="/public/static/libs/lazy-load-img/default.png">-->
                    <!--<img data-src="{$vo}" src="/public/static/libs/lazy-load-img/default.png" class="lazy" data-lazyload="{$vo}" data-preview-src="{php}echo strtr($vo,['/thumb/'=>'/']){/php}">-->
                <img src="{$vo}" data-key="{$k}" data-preview-src="{php}echo strtr($vo,['/thumb/'=>'/']){/php}" data-preview-group="1" data-content=""/>
                {/volist}
            </div>
            {/notempty}
        </div>
        <!--<div class="bg_bar"></div>-->

    </div>
</div>
{if condition="$reward_param['allow_reward'] eq 1"}
<div id="reword">
    <div class="award" data-status="{$has_reward}">
        赏
    </div>
    <p>已有{php}echo count($reward_data);{/php}人打赏作者</p>
</div>
{/if}
<div class="get_score">
    {notempty name="data['reward']['userList']"}
    <p class="get_score_desc">
        <span>{$data['reward']['userNumber']}人评价</span><span>共{$data['reward']['score'][0]['value']}财富</span>
    </p>
    {/notempty}
    <div class="get_score_body">
        <div class="score">
            {notempty name="data['ratelist']"}
            <div class="score_box">
                {volist name="data['ratelist']['user_arr']" id="vo"}
                <img src="{$vo['avatar']}" width="36" height="36" class="avatar-img" data-id="{$vo['uid']}">
                {/volist}
            </div>
            <img src="/public/static/topic/img/more.png" width="36" height="36" id="get-more"
                 data-href="{:config('website_domain')}{:url('topic/topic_post/score',['pid'=>$data['id']])}">
            {else/}
            <p>内容不错就评个分吧！</p>
            {/notempty}
        </div>
        <div class="right_commen add_score" data-uid="{$data['authorid']}" data-score="{$data['remain_credit']['userful']|default=0}"
             data-pid="{$data['id']}" data-min="{$data['remain_credit']['lowest']}" data-max="{$data['remain_credit']['highest']}"  data-used="{$data['remain_credit']['used']}">
            <img src="/public/static/topic/img/score.png" width="36" height="36">
        </div>
    </div>
</div>
<div style="height: .5rem;width: 100%;background: #F4F4F4;"></div>

<div class="sort_comment">
    <span>全部评论</span>
    <span class="select_sort"><img src="/public/static/topic/img/desc.png">倒序</span>
</div>
<div class="comment-box">
    {notempty name="data['comment']"}
    {volist name="data['comment']" id="vo"}
    <div class="comment">
        <div class="avtar"><img src="{$vo['useravatar']}" width="36" height="36" class="avatar-img" data-id="{$vo['uid']}"></div>
        <div class="comment-content">
            <p class="avtar-name"><span>{$vo['username']}</span>
                <span class="floor" id="{php}echo strtr($vo['floor'],['楼'=>'']);{/php}">{$vo['floor']}</span>
                <!--<span class="floor"></span>-->
                {if condition="$vo['credit_sum'] gt 0"}
                <span class="show_score"><a href="javascript:;" class="jifen" data-pid="{$vo['id']}"><img
                        src="/public/static/topic/img/jifen.png">{$vo['credit_sum']}财富</a></span>
                {/if}
                <span class="edit edit-comment" data-uid="{$vo['uid']}"  data-pid="{$vo['id']}" data-edit="{$vo['edit_url']}" data-del="{$vo['del_url']}"  data-score="{$vo['credit']['userful']|default=0}"
                      data-min="{$vo['credit']['lowest']}" data-comment="1" data-max="{$vo['credit']['highest']}"  data-used="{$vo['credit']['used']}"><img
                        src="/public/static/topic/img/edit.png"></span></p>
            {if condition="empty($vo['managePanel']) eq false"}
            <!--<span class="edit edit-comment" data-edit="{$vo['managePanel'][0]['action']}" data-del="{$vo['managePanel'][1]['action']}"><img src="/public/static/topic/img/edit.png"></span></p>-->
            {/if}
            </p>
            <p class="comments comment-content">{$vo['content']}</p>
            {notempty name="vo['pic']"}
            <p class="comments">
                {volist name="vo['pic']" id="v" key="k"}
                <!--<img class="lazy" data-lazyload="{$v}" data-preview-src="" data-preview-group="1" src="/public/static/libs/lazy-load-img/default.png">-->
                <!--<img  data-src="{$v}"  src="/public/static/libs/lazy-load-img/default.png" class="lazy" data-lazyload="{$v}" data-preview-src="" data-preview-group="1">-->
                <img src="{$v}" data-key="{$k}" data-preview-src="{php}echo strtr($vo,['/thumb/'=>'/']){/php}" data-preview-group="1" data-content=""/>
                <!--<img src="{$v}" data-key="{$k}" data-preview-src="{php}echo strtr($vo,['?x-oss-process=image/resize,w_320'=>'']){/php}" data-preview-group="1" data-content=""/>-->
                {/volist}
            </p>
            {/notempty}
            {if condition="$vo['is_quote'] eq 1"}
            <div class="replay" style="font-size: small">
                {php}
                echo str_replace(array("\r\n", "\r", "\n"), "<br>", $vo['quote_content']);
                {/php}
            </div>
            {/if}
            <p class="comment-time"><span>{$vo['ctime']}</span> · <span data-id="{$vo['id']}" class="add_comment"  data-tid="{$vo['tid']}" data-pid="{$vo['pid']}">回复> </span>
            </p>
        </div>
    </div>
    {/volist}
    {/notempty}
</div>


<div id="sheet1" class="mui-popover mui-popover-bottom mui-popover-action ">

    <!-- 可选择菜单 -->
    <ul class="mui-table-view">
        <li class="mui-table-view-cell">
            <a href="#" id="edit_comment">编辑评论</a>
        </li>
        <li class="mui-table-view-cell">
            <a href="javascript:;" id="del_comment">删除评论</a>
        </li>
        <li class="mui-table-view-cell">
            <a href="javascript:;" id="review" class="add_score" data-score="{$remain_score|default=0}">评分</a>
        </li>
    </ul>
    <!-- 取消菜单 -->
    <ul class="mui-table-view">
        <li class="mui-table-view-cell">
            <a href="#sheet1"><b>取消</b></a>
        </li>
    </ul>
</div>

<!--评分开始-->
<div class="mui-popup mui-popup-in pingfen" style="display: none;">
    <div class="mui-popup-inner">
        <div class="mui-popup-title">评分</div>
        <div class="mui-popup-text"></div>
        <div class="mui-popup-input">
            <input type="text" autofocus="autofocus" placeholder="请输入您的评论分数" class="sore">
            <span style="text-align: right" class="rand_word">随机一句</span>
            <textarea autofocus="" placeholder="输入您的评分理由" class="reason"></textarea>
            <input type="hidden" name="remain_score" value="">
            <input type="hidden" name="min" value="">
            <input type="hidden" name="max" value="">
            <input type="hidden" name="used" value="">
            <input type="hidden" name="pid" value="">
            <input type="hidden" name="to_uid" value="">
            <input type="hidden" name="comment" value="">
        </div>
    </div>
    <div class="mui-popup-buttons"> <span class="mui-popup-button cancel">取消</span><span class="mui-popup-button mui-popup-button-bold sure">确定</span>

    </div>
</div>
<!--评分结束-->

<!--打赏开始-->
<div class="mui-popup mui-popup-in reward" style="display: none;">
    <div class="mui-popup-inner">
        <div class="mui-popup-title">打赏</div>
        <div class="mui-popup-text" style="text-align: left;">您的打赏，会支撑我们提供更加优质的内容</div>
        <div class="mui-popup-input reward_box">
            {volist name="reward_param['extnums']" id="vo"}
                <span data-money="{$vo}">{$vo}海川币</span>
            {/volist}
            <!--<span class="other-charge" data-money="">其他</span>-->
            <!--<div class="money-change">-->
                <!--<input class="mui-input-numbox mui-input-row hidemoney" type="text" placeholder="自定义金额"  onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" />-->
                <!--&lt;!&ndash;<p><span class="yuan">0.00</span>元</p>&ndash;&gt;-->
            <!--</div>-->
        </div>
    </div>
    <div class="mui-popup-buttons">
        <span class="mui-popup-button reward_cancel">取消</span>
        <span class="mui-popup-button mui-popup-button-bold reward_sure">确定</span>
    </div>
</div>


<!--打赏结束-->

<div class="mui-popup-backdrop mui-active" style="display: none;"></div>
<!--上拉加载-->
<div class="weui-loadmore">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载</span>
</div>
<!--上拉加载解暑-->

</body>
<script src="/public/static/libs/weui/lib/jquery-2.1.4.js"></script>
<script src="/public/static/libs/weui/jquery-weui.js"></script>

<script type="text/javascript" src="/public/static/libs/mui/mui-3.4.0/dist/js/mui.js"></script>
{if condition="$android eq 0"}
<script type="text/javascript" src="/public/static/libs/weui/lib/mui.previewimage.js"></script>
<script type="text/javascript" src="/public/static/libs/weui/lib/mui.zoom.js"></script>
{/if}
<!--<script src="/public/static/libs/lazy-load-img/lazy-load-img.min.js"></script>-->
<!--<script type="text/javascript" src="/public/static/libs/weui/js/jquery-weui.js"></script>-->

<script type="text/javascript">
//初始化
mui.init();
var page = 1;
var storage=window.localStorage;
var sort=storage.getItem('sort');
//顶部悬浮
var avatarH=$('#follow').offset().top;
$(document).scroll(function(){
	var sb=$(document).scrollTop();
	if(sb>avatarH){
		$('.xuanfu').show();
	}else{
		$('.xuanfu').hide();
	}
})


//点击关注
$('.head-img').click(function(){
	$.ajax({
		type:"post",
		data:{
			user_id:'',
			to_uid:''
		},
		contentType: "application/json;charset=utf-8",
		url:'https://app.hcbbs.com/index.php/topic/friend/add_follow',
		success:function(res){
			if(res.data==200){
				$('.follow').text('已关注')
			}
			
		}
	});
})
//实时判断当前的排序
if(sort=='asc'){
    $('.select_sort').html('<img src="/public/static/topic/img/asc.png">正序');
}else{
    $('.select_sort').html('<img src="/public/static/topic/img/desc.png">倒序');
}

    //打赏js
    var pid="{$data['id']}";
    var tid="{$data['tid']}";
    var authorid="{$data['authorid']}";
    var uid="{$uid}";
    var allow_repeat_reward="{$reward_param['repeat']}";
    var accessToken="{$accessToken}";
    var accessSecret="{$accessSecret}";

    FastClick.attach(document.body);

    var ua = navigator.userAgent.toLowerCase();
    if (/iphone|ipad|ipod/.test(ua)) {
        mui.previewImage();
    }
    //选择金额
    mui('body').on('tap', '.reward_box span', function() {
        $(this).addClass('reward_check').siblings().removeClass('reward_check');
        var money=$(this).data('money');
        $('.money-change input').hide();
        $('.hidemoney').val('');
    });

    //自选金额
    mui('body').on('tap', '.other-charge', function() {
        $('.money-change input').show();
        var mon=$('.reward_check').data('');
    });

    //取消打赏
    mui('body').on('tap', '.reward_cancel', function() {
        $('.reward').css('display', 'none');
        $('.mui-popup-backdrop').css('display', 'none');

    });

    //打赏事件弹出
    mui('body').on('tap', '.award', function() {
        var status=this.getAttribute('data-status');
        if(status==1 && allow_repeat_reward==0){
            mui.alert("不允许重复打赏",function () {
                return false;
            });
        }
        $('.reward').css('display', 'block');
        $('.mui-popup-backdrop').css('display', 'block');

    });


    //确定打赏
    mui('body').on('tap', '.reward_sure', function() {
        var mon=$('.reward_check').data('money');
        var t_money=$('.hidemoney').val();
        var money=mon==''?t_money:mon;
        if(money==undefined){
            $('.reward').css('display', 'none');
            mui.alert("请选择要打赏的海川币",function () {
                $('.reward').css('display', 'block');
            });
            return false;
        }
        if( t_money=='' && mon==undefined){
            $('.reward').css('display', 'none');
            mui.alert('不能为空',function(){
                $('.reward').css('display', 'block');
            });
            return false;
        }

        if( t_money=='' && mon==''){
            $('.reward').css('display', 'none');
            mui.alert('不能为空',function(){
                $('.reward').css('display', 'block');
            });
            return false;
        }

        mui.post('/index.php/topic/topic_post/reward', {
            uid: uid,
            pid: pid,
            score: money,
            tid: tid,
            to_uid:authorid,
            accessToken:accessToken,
            accessSecret:accessSecret
        }, function (e) {
            $('.reward').css('display', 'none');
            mui.alert(e.msg, function () {
                if(e.code==200){
                    $('.mui-popup-backdrop').css('display', 'none');
                    window.location.reload();
                }else{
                    $('.reward').css('display', 'block');
                }
            });
        }, 'json');

    });

    function comment(comment_id, tid, pid) {
        var ua = navigator.userAgent.toLowerCase();
        if (/iphone|ipad|ipod/.test(ua)) {
            add_comment(comment_id, tid, pid);
        } else {
            topics.add_comment(comment_id, tid, pid);
        }
    }
    function go_pages(url, title) {
        var ua = navigator.userAgent.toLowerCase();
        if (/iphone|ipad|ipod/.test(ua)) {
            go_urls(url, title);
        } else {
            topic.go_url(url, title);
        }
    }
    function go_page(url, title) {
        var ua = navigator.userAgent.toLowerCase();
        if (/iphone|ipad|ipod/.test(ua)) {
            go_url(url, title);
        } else {
            topic.go_url(url, title);
        }
    }
    function back() {
        var ua = navigator.userAgent.toLowerCase();
        if (/iphone|ipad|ipod/.test(ua)) {
            back_page();
        } else {
            viewPage.back_page();
        }
    }
    function show_image(imgs,key) {
        var ua = navigator.userAgent.toLowerCase();
        if (/iphone|ipad|ipod/.test(ua)) {

        }else{
            image.img_preview(imgs,key);
        }
    }

    //安卓图片预览
    $('body').on('tap','.news_zixun_img img',function () {
        var img=$(this).closest('.news_zixun_img').children();
        var imgs=new Array;
        $.each(img,function (a,b) {
            imgs[a]=$(b).attr('data-preview-src');
        });
        var key=$(this).attr('data-key');
        key=key-1;
        show_image(imgs,key);
    });

    $('body').on('tap','.comments img',function () {
            var img=$(this).closest('.comments').children();
            var imgs=new Array;
            $.each(img,function (a,b) {
                imgs[a]=$(b).attr('data-preview-src');
            });
            var key=parseInt($(this).attr("data-key"));
            show_image(imgs,key);
    });


    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
        return (false);
    }
    $(function () {
        page=1;
        getData();
        var uid="{$uid}";
        //列表图片宽高比例一致
        var send_w = $('.news_zixun .news_zixun_img img').width();
        var score_box = $('.score_box').width();
        $('.news_zixun .news_zixun_img img').height(send_w);

        //评分 人 多于四位  score_box宽度固定
        if (score_box > 150) {
            $('.score_box').addClass('score_width');
        }

        //点击更多  弹出底部
        $('body').on('tap', '.edit-comment', function () {
            console.log($('#del_comment').parent());
            var edit_href = $(this).attr("data-edit");
            var del_href = $(this).attr("data-del");
            var score=$(this).attr("data-score");
            var min=$(this).attr("data-min");
            var max=$(this).attr("data-max");
            var pid=$(this).attr("data-pid");
            var used=$(this).attr("data-used");
            var to_uid=$(this).attr('data-uid');
            var comment=$(this).attr("data-comment");
//            jQuery('#edit_comment').parent().css("display", "none");
//            jQuery('#del_comment').parent().css("display", "none");
            if (edit_href != '') {
                $('#edit_comment').attr({'data-href': edit_href});
            } else {
                $('#edit_comment').parent().css("display", "none");
            }
            if(score){
                $("#review").attr({'data-score':score,'data-min':min,'data-max':max,'data-pid':pid,'data-used':used,'data-comment':comment,'data-uid':to_uid});
            }
            if (del_href != '') {
                $('#del_comment').attr({'data-href': del_href});
            } else {
                $('#del_comment').parent().css("display", "none");
            }
            mui('#sheet1').popover('toggle');
        });
        mui('body').on('tap', '#get-more', function () {
            var url = $(this).attr('data-href');
            go_page(url, '评分列表');
        });
        mui('body').on('tap', '.rand_word', function () {
            var word=["说得真好","不错，赞一个","给力","有才","不错，支持下"];
            var num=parseInt(Math.random()*5);
            console.log(num);
            $('.reason').val(word[num]);
        });
        mui('body').on('tap', '#edit_comment', function () {
            var url=this.getAttribute('data-href');
            mui('#sheet1').popover('toggle');
            go_page(url, '编辑评论');
        });
        mui('body').on('tap', '.add_comment', function () {
            var comment_id=this.getAttribute('data-id');
            var tid=this.getAttribute('data-tid');
            var pid=this.getAttribute('data-pid');
            comment(comment_id, tid, pid)
        });
        mui('body').on('tap', '.avatar-img', function () {
            var user_id=this.getAttribute('data-id');
            var url="{:config('website_domains')}/index.php/topic/friend/user_info/user_id/"+user_id+'/from_uid/'+uid;
            go_page(url,'主页');
        });
        mui('body').on('tap', '#del_comment', function () {
            var href = this.getAttribute("data-href");
            mui('#sheet1').popover('toggle');
            var btnArray = ['取消', '删除'];
            mui.confirm('确认删除？', '提示', btnArray, function(e) {
                if (e.index == 1) {
                    mui.get(href, '', function (result) {
                        if(result.code==200){
                            mui.alert(result.msg,function () {
                                window.location.reload();
                            });
                        }else{
                            mui.alert(result.msg);
                        }
                    }, 'json');
                }
            });
        });
        mui('body').on('tap','a',function () {
            var url=this.getAttribute('href');
            var pid=parseInt(this.getAttribute('data-pid'));
            var id=this.getAttribute("id");
            if(id=="review"){
                return false;
            }
            if(id=='del_comment'){
                return false;
            }
            if(url=='javascript:;' && pid>0){
                var score_url = "{:config('website_domains')}{:url('topic/topic_post/score')}?pid=" + pid;
                go_page(score_url, '评分列表');
                return false;
            }
            if(url.indexOf('forum.php')>=0){
                return false;
            }
            console.log(url);
            if(url.indexOf("#")<0){
                console.log(1);
                go_page(url,'');
            }
        });
        //评分
        mui('body').on('tap', '.add_score',function() {
            var remain_score = this.getAttribute('data-score');$('input[name="remain_score"]').val(remain_score);
            var min = this.getAttribute('data-min');$('input[name="min"]').val(min);
            var max = this.getAttribute('data-max');$('input[name="max"]').val(max);
            var used = this.getAttribute('data-used');$('input[name="used"]').val(used);
            var pid = this.getAttribute('data-pid');$('input[name="pid"]').val(pid);
            var to_uid = this.getAttribute('data-uid');$('input[name="to_uid"]').val(to_uid);
            var comment=this.getAttribute('data-comment');$('input[name="comment"]').val(comment);

            if (remain_score == null) {mui.alert("暂无评分权限");return false;}
            var tips='每次评分最多'+max+'，最少'+min+'，今日已使用'+used+'财富，您今日剩余可评' + remain_score + '财富';
            $('.mui-popup-text').text(tips);
            $('#sheet1').hide();
//            add_score(remain_score,min,max,used,pid,to_uid,comment);
            $('.pingfen').css('display','block');
            $('.mui-popup-backdrop').css('display','block');
        });

        //点击取消按钮
        mui('body').on('tap','.cancel',function(){
            var comment=$('input[name="comment"]').val();
            $('.pingfen').css('display','none');
            $('.mui-popup-backdrop').css('display','none');
            if (comment == 1) {
                mui('#sheet1').popover('toggle');
            }
        });
        //点击确定按钮
        mui('body').on('tap','.sure',function(){
            var score=$('.sore').val();
            var reason=$('.reason').val();
            var remain_score = $('input[name="remain_score"]').val();
            var min = $('input[name="min"]').val();
            var max = $('input[name="max"]').val();
            var used = $('input[name="used"]').val();
            var pid = $('input[name="pid"]').val();
            var to_uid = $('input[name="to_uid"]').val();
            var comment=$('input[name="comment"]').val();
            if (score == '') {
                $('.pingfen').css('display','none');
                $('.mui-popup-backdrop').css('display','none');
                mui.alert("请输入评分数",function () {
                    $('.pingfen').css('display','block');
                    $('.mui-popup-backdrop').css('display','block');
                });
                return false;
            }else if(reason==''){
                $('.pingfen').css('display','none');
                $('.mui-popup-backdrop').css('display','none');
                mui.alert("请输入评分理由",function () {
                    $('.pingfen').css('display','block');
                    $('.mui-popup-backdrop').css('display','block');
                });
                return false;
            } else {
                if ((remain_score-score)<0) {
                    $('.pingfen').hide();
                    mui.alert("不得超出剩余评分额度",function(){
                        $('.pingfen').show();
                    });
                } else {
                    var uid="{$uid}";
                    var tid = "{$data['tid']}";
                    mui.post('/index.php/topic/topic_post/score', {
                        uid: uid,
                        pid: pid,
                        score: score,
                        tid: tid,
                        to_uid:to_uid,
                        reason:reason
                    }, function (e) {
                        $('.pingfen').css('display','none');
                        $('.mui-popup-backdrop').css('display','none');
                        mui.alert(e.msg, function () {
                            if(e.code==200){
                                window.location.reload();
                            }
                            $('.sore').val('');
                            $('.reason').val('');
                            $('.mui-backdrop-action').remove();
                        });
                    }, 'json');
                }
            }
        });




        function selectText(textbox, startIndex, stopIndex) {
            if (textbox.setSelectionRange) {
                textbox.setSelectionRange(startIndex, stopIndex);
            } else if (textbox.createTextRange) {
                var range = textbox.createTextRange();
                range.collapse(true);
                range.moveStart('character', startIndex);
                range.moveEnd('character', stopIndex - startIndex);
                range.select();
            }
            textbox.focus();
        }

        {if condition="$android"}
            $(document.body).pullToRefresh();
            $(document.body).on("pull-to-refresh", function() {
                //do something
                window.location.reload();

            });

        {/if}
        //上拉加载
        var loading = false;  //状态标记
        $(document.body).infinite(100).on("infinite", function() {
            if(loading) return;
            getData();
            loading = true;
            setTimeout(function() {
                loading = false;
            }, 1500);   //模拟延迟
        });

        //评论排序
				mui('body').on('tap', '.select_sort', function() {
					if($(this).text()=='倒序'){
					    sort='asc';
					    page=1;
						storage.setItem("sort",sort);
						$(this).html('<img src="/public/static/topic/img/asc.png">正序');
						getData(1);
					}else{
					    sort='desc';
					    page=1;
						storage.setItem("sort",sort);
						$(this).html('<img src="/public/static/topic/img/desc.png">倒序');
						getData(1);
					}
				});
		//评论排序结束
    })

function  getData() {
    //业务逻辑代码，比如通过ajax从服务器获取新数据；
    // ......
    //注意：
    //1、加载完新数据后，必须执行如下代码，true表示没有更多数据了：
    //2、若为ajax请求，则需将如下代码放置在处理完ajax响应数据之后;
    var sort=storage.getItem('sort');
    var refersh=arguments[0];
    if(sort=='' ||sort==undefined){
        sort='asc';
    }
    $.ajax({
        type: "get",
        url: "/index.php/topic/topic_post_comment/getCommentList?accessSecret={$accessSecret}&accessToken={$accessToken}&id={$id}&tid={$tid}&user_id={$uid}&page=" + page+'&sort='+sort,
        dataType: 'json',
        success: function (e) {
            if (e.code == 200) {
                var comment = '';
                $.each(e.data, function (a, b) {
                    comment += '<div class="comment">';
                    comment += '<div class="avtar"><img src="' + b.useravatar + '" width="36" height="36" class="avatar-img" data-id="'+b['uid']+'"></div>';
                    comment += '<div class="comment-content">';
                    comment += '<p class="avtar-name"><span>' + b.username + '</span>';
                    comment += '<span class="floor" id="' + b.floor.replace('楼', '') + '">' + b.floor + '</span>';
                    //                            comment += '<span class="floor"></span>';
                    if (b.credit_sum > 0) {
                        comment += '<span class="show_score"><a href="javascript:;" class="jifen" data-pid="' + b.id + '"><img src="/public/static/topic/img/jifen.png">' + b.credit_sum + '财富</a></span>';
                    }
                    if (b.managePanel.length > 0) {
                        //comment +='<span class="edit" data-pid='+b.pid+'><img src="img/edit.png"></span>';
                    }
                    comment += '<span class="edit edit-comment"   data-comment="1"  data-uid="'+b['uid']+'" data-edit="' + b.edit_url + '" data-del="' + b.del_url + '" data-score="'+b['credit']['userful']+'"data-pid="'+b['id']+'" data-min="'+b['credit']['lowest']+'" data-max="'+b['credit']['highest']+'"  data-used="'+b['credit']['used']+'"><img src="/public/static/topic/img/edit.png"></span></p>';
                    comment += '</p><p class="comments">' + b.content + '</p>';
                    if(b['pic'].length>0){
                        comment+='<p class="comments">';
                        $.each(b['pic'],function (a,b) {
//                                    comment+='<img class="lazy" data-original="'+b+'" data-preview-src="'+b.replace('/thumb/','/')+'" data-preview-group="1">';
//                                    comment+='<img class="lazy" data-original="'+b+'"data-src="'+b+'" data-preview-src="'+b.replace('/thumb/','/')+'" data-preview-group="1">';
                            comment+='<img data-key="'+a+'" src="'+b+'" data-preview-src="'+b.replace('/thumb/','/')+'" data-preview-group="1" data-content=""/>';
//                            comment+='<img data-key="'+a+'" src="'+b+'" data-preview-src="'+b.replace('?x-oss-process=image/resize,w_320','')+'" data-preview-group="1" data-content=""/>';
                        });
                        comment+='</p>'
                    }
                    comment += '<p class="comment-time"><span>' + b.ctime + '</span> · <span class="add_comment" data-id="' + b.id + '" data-tid="'+b.tid+'" data-pid="'+b.pid+'"">回复> </span></p>';
                    comment += '</div></div>';
                });
                if(refersh){
                    $('.comment-box').html(comment);
                    $(document.body).infinite(100);
                    $('.weui-loading').show();
                    $('.weui-loadmore__tips').text('正在加载...');
                }else{
                    $('.comment-box').append(comment);
                }
                /*var lazyLoadImg = new LazyLoadImg({
                 el: document.querySelector('.comment-box'),
                 mode: 'default', //默认模式，将显示原图，diy模式，将自定义剪切，默认剪切居中部分
                 time: 300, // 设置一个检测时间间隔
                 complete: true, //页面内所有数据图片加载完成后，是否自己销毁程序，true默认销毁，false不销毁
                 position: { // 只要其中一个位置符合条件，都会触发加载机制
                 top: 0, // 元素距离顶部
                 right: 0, // 元素距离右边
                 bottom: 0, // 元素距离下面
                 left: 0 // 元素距离左边
                 },
                 before: function() { // 图片加载之前执行方法
                 },
                 success: function(el) { // 图片加载成功执行方法
                 el.classList.add('success')
                 },
                 error: function(el) { // 图片加载失败执行方法
                 el.src = '/public/static/libs/lazy-load-img/error.png'
                 }
                 });*/
                page++;
            } else {
                if (e.data.length == 0) {
                    $('.weui-loading').hide();
                    $('.weui-loadmore__tips').text('已加载完毕');
                    $(document.body).destroyInfinite();
                    return false;
                }
            }
        }

    });

}


</script>

</html>